package org.xiaoyu.rpc;

import org.xiaoyu.rpc.common.exception.RpcException;
import org.xiaoyu.rpc.remoting.transport.cllient.future.RpcFuture;

/**
 * Created By Have
 * 2021/7/28 23:35
 */
public class RpcContext {
    private static final ThreadLocal<RpcFuture> futureLocal = new ThreadLocal<>();

    public static RpcFuture getFuture() {
        RpcFuture rpcFuture = futureLocal.get();
        if (rpcFuture == null) {
            throw new RpcException("Illegal operation, the future is null");
        }
        return rpcFuture;
    }

    public static void setFuture(RpcFuture rpcFuture) {
        if (rpcFuture == null) {
            throw new RpcException("Illegal operation, the future is null");
        }
        futureLocal.set(rpcFuture);
    }
}
